<?php

namespace App\Ma\States;

use App\Constants\Users;
use App\Ma\Entities\MatrixUtils;
use App\Ma\Weights\BaseWeight;
use App\Model\RoundActionModel;
use App\Model\RoundsModel;
use App\Model\UsersModel;

/**
 * 摸牌状态
 * Class MoState
 * @package App\Ma\States
 */
class MoState extends BaseState
{
    /**
     * 当前牌值可自摸
     * @var array
     */
    public $canGang = [];

    /**
     * 是否自摸
     * @var bool
     */
    public $canZiMo = false;

    /**
     * @var UsersModel
     */
    public $user;

    public $weight;

    /**
     * 胡牌的牌型
     * @var int
     */
    public $huType = 0;

    public function __construct(RoundActionModel $action, RoundsModel $round)
    {
        parent::__construct($action, $round);
        $this->user = $action->User()->first();
        $this->init();
        $this->initWeight();

    }

    private function init()
    {
        // 检测杠
        $this->canGang = MatrixUtils::canAnGangValues($this->matrix->cardMatrix);

        // 检车是否自摸
        $this->canZiMo = $this->matrix->checkHu($huType);
        $this->huType = $huType;

    }

    private function initWeight()
    {
        if ($this->user->type === Users::TYPE_ROBOT) {
            $this->weight = new BaseWeight($this->matrix);
        }
    }

}